package com.luoran.bartalks.utils;

import java.util.Comparator;
import java.util.Map;
import java.util.TreeMap;

//Map比较器
public class MapKeyComparator implements Comparator<Double> {

	@Override
	public int compare(Double o1, Double o2) {
		return o1.compareTo(o2);
	}

	/**
	 * 使用 Map按key进行排序
	 * 
	 * @param map
	 * @return
	 */
	public static Map<Double, String> sortMapByKey(Map<Double, String> map) {
		if (map == null || map.isEmpty()) {
			return null;
		}
		Map<Double, String> sortMap = new TreeMap<Double, String>(new MapKeyComparator());
		sortMap.putAll(map);
		return sortMap;
	}
}
